<template>
  <a-modal
    :title="title"
    :width="1000"
    :visible="visible"
    :confirmLoading="confirmLoading"
    :destroyOnClose="true"
    @cancel="handleCancel"
    :footer="null"
  >
    <div class="DetailTitle">
      <a-row style="margin-bottom: 10px">
        <a-col :span="8" :offset="8" style="text-align: center">
          <span class="title">{{ title }}</span>
        </a-col>
      </a-row>
      <a-row style="margin-bottom: 15px">
        <a-col :span="8">
          <span>单位名称：{{ heardData.enterpriseUnit }}</span>
        </a-col>
        <a-col :span="8" :offset="8">
          <div class="Datenper">
            <span>所属属期：{{ heardData.reportYear }}年{{ heardData.reportMonth }}月</span>
            <span>单位：{{heardData.currency}}</span>
          </div>
        </a-col>
      </a-row>
      <a-table
        :columns="columns"
        :data-source="dataSource"
        row-key="id"
        :loading="loading"
        :pagination="false"
        class="antableClass"
        :scroll="{ y: 450 }"
      >
      </a-table>
    </div>
  </a-modal>
</template>

<script>
import { columnsfz, columnslr, columnsll } from './columns'
import { httpAction, getAction, postAction, deleteAction } from '@/api/manage'
export default {
  name: 'CheackDetail',
  data() {
    return {
      title: '',
      visible: false,
      confirmLoading: false,
      queryParam: {
        reportYear: '',
        reportMonth: '12',
        unitCode: '',
      },
      url: {
        list: '',
      },
      loading: false,
      ListUrl: [
        '/sjzxzbfx/sjzcfz/queryZcfzInfo',
        '/sjzxzbfx/sjlr/queryLrbInfo',
        '/sjzxzbfx/sjZxzyEnterpriseCashFlow/queryXjllInfo',
      ],
      columns: [],
      dataSource: [],
      heardData: {},
    }
  },
  methods: {
    handleOk() {},
    handleCancel() {},
    show({ name, seriesName }) {
      // 参数一：x轴年份 参数二：ecahts表名
      this.getlistUrl(seriesName)
      this.queryParam.reportYear = name
      this.queryParam.unitCode = this.$attrs.unitCode
      this.loadData()
      this.visible = true
    },
    loadData() {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      this.loading = true
      getAction(this.url.list, this.queryParam).then((result) => {
        if (result.success) {
          this.heardData = Object.assign({}, result.result[0])
          this.dataSource = result.result
        }
        this.loading = false
      })
    },
    getlistUrl(seriesName) {
      // 根据表名获取对应url
      switch (seriesName) {
        case '资产负债率':
        case '年应收客户合同工程款增（降）幅':
        case '年度经营性有息负债增（降）幅':
          this.url.list = this.ListUrl[0]
          this.title = '资产负债表'
          this.columns = columnsfz(this)
          break
        case '营业收入增（降）幅':
          this.url.list = this.ListUrl[1]
          this.title = '利润表'
          this.columns = columnslr(this)
          break
        case '经营活动现金净流量':
        case '投资活动现金净流量':
          this.url.list = this.ListUrl[2]
          this.title = '现金流量表'
          this.columns = columnsll(this)
          break
        default:
          this.handleCancel()
          this.$message.warning('不存在详情页');
      }
    },
    handleCancel() {
      this.visible = false
    },
  },
}
</script>

<style lang="less" scoped>
@import '~@assets/less/tableTheme.less';
.DetailTitle {
  margin: 0px 18px 10px;
  .title {
    font-size: 20px;
    font-weight: 700;
    color: black;
  }
  .Datenper {
    display: flex;
    justify-content: space-between;
  }
}
</style>